package pl.mchaniewski.ryneczek.utilities;

import java.util.Map;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.Cookie;

public class CookieUtil {
    public static final int COOKIE_MAX_AGE = 31536000;

    public static Cookie getCookie(String name) {
        ExternalContext ec = FacesContext.getCurrentInstance()
                .getExternalContext();
        Map<String, Object> cookies = ec.getRequestCookieMap();

        return (Cookie) cookies.get(name);
    }

    public static void addCookie(String name, String value,
            Map<String, Object> properties) {
        ExternalContext ec = FacesContext.getCurrentInstance()
                .getExternalContext();
        ec.addResponseCookie(name, value, properties);
    }
}
